package cn.doitedu.producer.low;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author: 深似海
 * @Site: <a href="www.51doit.com">多易教育</a>
 * @QQ: 657270652
 * @Date: 2024/7/21
 * @Desc: 学大数据，上多易教育
 * 从控制台接收用户输入的“行为事件”json数据
 * 并将数据发送给“运算引擎”
 **/
public class ProducerStarter_v1 {

    public static void main(String[] args) throws InterruptedException, IOException {


        Socket socket = new Socket("localhost", 9090);
        OutputStream outputStream = socket.getOutputStream();


        // 从控制台接收数据
        Scanner scanner = new Scanner(System.in);
        boolean exit = false;

        while (!exit) {
            String line = scanner.nextLine();

            if (line.equals("bye!")) {
                exit = true;
                System.out.println("程序即将退出......");
            } else {
                // 将收到的数据，通过socket连接发送给“运算引擎”
                //System.out.println("==>" + line);
                outputStream.write((line + "\n").getBytes()  );
            }
        }


    }
}
